home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 38
/
Amiga Format CD38 (1999-03-15)(Future Publishing)(GB)(Track 1 of 3)[!][issue 1999-04].iso
/
-seriously_amiga-
/
misc
/
felix
/
source
/
flxclasses.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1999-01-25
|
8KB
|
353 lines
//*************************************************************************//
// Filename: mzclasses.cpp
// Autor: Christian Taulien of Strange Intelligence
// Purpose: implementation of the mzclasses
// Creation: 18. März 1998
//*************************************************************************//
#include "flxclasses.h"
#include "processcomm.h"
#include "freshlocale.h"
#include <string.h>
#include <stdio.h>
#include <clib/exec_protos.h>
#include <clib/dos_protos.h>
#include <clib/intuition_protos.h>
#include <clib/utility_protos.h>
extern "C" void NewList(struct List *list);
char *createNameFromInstance(struct APIInstance *arg_poAPIInstance)
/*S*/
{
char *name = NULL;
TRACE("Entry");
if (arg_poAPIInstance->api_Name)
{
ULONG len = strlen(arg_poAPIInstance->api_Name);
name = new char [len+4];
// if the speicher could be reserviert
if (name)
{
strcpy(name, arg_poAPIInstance->api_Name);
} // if
} // if
return name;
}
/*E*/
//******************************************************************//
//******************************************************************//
//
// FLXNodeC
//
//******************************************************************//
//******************************************************************//
FLXNodeC::FLXNodeC(struct APIInstance *arg_poInstance, FLXWatchListC *arg_poWatchList)
/*S*/
{
TRACE("Konstruktor");
// init the baseclassmembers
ln_Succ = NULL;
ln_Pred = NULL;
ln_Type = NT_USER;
ln_Pri = 0;
// now our members
m_ulFlags = FLXMASK_DEFAULT;
m_poAPIInstance = arg_poInstance;
ln_Name = createNameFromInstance(arg_poInstance);
m_poNotifyReq = new struct NotifyRequest;
if (m_poNotifyReq && arg_poWatchList->getMsgPort())
{
memset(m_poNotifyReq, 0, sizeof(struct NotifyRequest));
m_poNotifyReq->nr_Name = ln_Name;
m_poNotifyReq->nr_UserData = (ULONG) this; // to find us
m_poNotifyReq->nr_Flags = NRF_SEND_MESSAGE;
m_poNotifyReq->nr_stuff.nr_Msg.nr_Port = arg_poWatchList->getMsgPort();
StartNotify(m_poNotifyReq);
}
else
{
TRACE("Kein Speicher oder kein MessagePort");
} // if
TRACE(getFileName());
} // FLXNodeC::FLXNodeC()
/*E*/
FLXNodeC::~FLXNodeC()
/*S*/
{
TRACE("Destruktor");
TRACE(getFileName());
// wenn NotifyRequest-Vorhanden
if (m_poNotifyReq)
{
EndNotify(m_poNotifyReq);
delete m_poNotifyReq;
} // if
if (ln_Name)
{
delete ln_Name;
} // if
// if the node is in a list
if (ln_Pred && ln_Succ)
{
Remove(this);
} // if
}
/*E*/
FLXNodeC *FLXNodeC::getNext(void)
/*S*/
{
TRACE("getNext()");
if (ln_Succ && ln_Succ->ln_Succ)
{
return (FLXNodeC *) ln_Succ;
} // if
return NULL;
}
/*E*/
FLXNodeC *FLXNodeC::getPrev(void)
/*S*/
{
TRACE("getPrev()");
if (ln_Pred && ln_Pred->ln_Pred)
{
return (FLXNodeC *) ln_Pred;
} // if
return NULL;
}
/*E*/
void FLXNodeC::reloadFile(void)
/*S*/
{
// wenn Verändert und weder versteckt, noch inaktiv
if (isModified() && !isHidden() && !isInactive())
{
struct EasyStruct request =
{
sizeof(struct EasyStruct),
0,
0,
NULL,
0
};
char *buffer = new char [strlen(glob_poCatalog->getString(T_NOTIFYASK))+2];
if (buffer)
{
request.es_Title = glob_poCatalog->getString(T_NOTIFYTITLE);
request.es_GadgetFormat = glob_poCatalog->getString(T_NOTIFYGADGETS);
sprintf(buffer, glob_poCatalog->getString(T_NOTIFYASK) ,ln_Name);
request.es_TextFormat = buffer;
LONG response = EasyRequestArgs((struct Window *) (m_poAPIInstance->api_Window), &request, NULL, NULL);
setModified(FALSE);
// wenn reload gewünscht
if (response==1)
{
TRACE("Ok. lade file nach");
SendeNachricht("remote",
FelixMessage::FLXMSG_REMOTECMD,
FLXTAG_REMOTECOMMAND, FLXREMOTECMD_RELOADFILE,
FLXTAG_FileName, getFileName(),
TAG_DONE);
} // if
delete [] buffer;
} // if
} // if
}
/*E*/
//******************************************************************//
//******************************************************************//
//
// FLXWatchListC
//
//******************************************************************//
//******************************************************************//
FLXWatchListC::FLXWatchListC()
/*S*/
{
TRACE("Konstruktor");
NewList(this);
m_poMsgPort = CreateMsgPort();
if (!m_poMsgPort)
{
TRACE("Kein Speicher");
} // if
} // FLXWatchListC::FLXWatchListC()
/*E*/
FLXWatchListC::~FLXWatchListC()
/*S*/
{
TRACE("Destruktor");
// wenn die Liste nicht leer ist
if (!IsListEmpty(this))
{
TRACE("Achtung: Liste ist nicht leer!!!");
FLXNodeC *pNode;
while (pNode = (FLXNodeC *) RemHead(this))
{
pNode->ln_Succ = NULL;
pNode->ln_Pred = NULL;
delete pNode;
} // while
} // if
if (m_poMsgPort)
{
// Port leeren
struct Message *pMsg;
while (pMsg = GetMsg(m_poMsgPort))
{
ReplyMsg(pMsg);
} // while
// Port löschen
DeleteMsgPort(m_poMsgPort);
} // if
} // FLXWatchListC::~FLXWacthListC()
/*E*/
BOOL FLXWatchListC::addWatch(struct APIInstance *arg_poInstance)
/*S*/
{
TRACE("addWatch()");
TRACE(arg_poInstance->api_Name);
// neuen Watch erzeugen
FLXNodeC *poWatch = new FLXNodeC(arg_poInstance, this);
if (poWatch)
{
// hänge diesen in die Liste ein
AddTail(this, poWatch);
}
else
{
TRACE("Kein Speicher");
return FALSE;
} // if
return TRUE;
}
/*E*/
FLXNodeC *FLXWatchListC::findWatch(struct APIInstance *arg_poInstance)
/*S*/
{
TRACE("findWatch()");
FLXNodeC *pNode = NULL;
// wenn die Watchliste nicht leer ist
if (!IsListEmpty(this))
{
pNode = (FLXNodeC *) lh_Head;
do
{
if (pNode->m_poAPIInstance == arg_poInstance)
{
return pNode;
} // if
} while (pNode = pNode->getNext());
} // if
return pNode;
}
/*E*/
FLXNodeC *FLXWatchListC::operator[](int arg_iIndex)
/*S*/
{
TRACE("ENTRY");
FLXNodeC *pNode = NULL;
// wenn die Watchliste nicht leer ist
if (!IsListEmpty(this))
{
int index = 0;
// hole 1. eintrag
pNode = (FLXNodeC *) lh_Head;
do
{
// wenn i.ten eintrag erreicht
if (index == arg_iIndex)
{
return pNode;
} // if
index++;
} while (pNode = pNode->getNext());
} // if
return pNode;
}
/*E*/
int FLXWatchListC::getSize(void)
/*S*/
{
TRACE("ENTRY");
int iSize = 0;
// wenn die Liste nicht leer ist
if (!IsListEmpty(this))
{
// hole 1. Eintrag
FLXNodeC *pNode = (FLXNodeC *) lh_Head;
for (iSize=1; pNode = pNode->getNext(); iSize++);
} // if
return iSize;
}
/*E*/
void FLXWatchListC::checkAccess(void)
/*S*/
{
FLXNodeC *pNode = NULL;
if (m_poMsgPort)
{
// geh' alle messages durch und markiere alle veränderten nodes
struct NotifyMessage *pMsg;
while (pMsg = (struct NotifyMessage *) GetMsg(m_poMsgPort))
{
pNode = NULL;
ULONG dummy = pMsg->nm_NReq->nr_UserData;
if (dummy)
{
pNode = (FLXNodeC *) dummy;
} // if
ReplyMsg((struct Message *) pMsg);
if (pNode)
{
TRACE("try modify");
// if the node is empfänglich for modification-notifies
if (!pNode->isInactive())
{
TRACE("modify set");
pNode->setModified(TRUE);
} // if
} // if
} // while
} // if
// wenn die Watchliste nicht leer ist
if (!IsListEmpty(this))
{
// für jedes modifieziert File...
pNode = (FLXNodeC *) lh_Head;
do
{
pNode->reloadFile();
} while (pNode = pNode->getNext());
} // if
}
/*E*/